using System;
using System.Collections.Generic;
using BSpec.Conventions;

namespace BSpec.Specification
{
    public class Concern : SpecificationElement
    {
        private readonly List<Scenario> _scenarios = new List<Scenario>();

        protected Concern(string name) : base(name)
        {
        }

        public Scenario[] Scenarios
        {
            get { return _scenarios.ToArray(); }
        }

        public void AddScenarioFor(Type testFixtureType)
        {
            var scenario = Scenario.Create(testFixtureType);

            if (_scenarios.HasElement(scenario))
            {
                _scenarios.GetElement(scenario).AddContextFor(testFixtureType);
            }
            else
            {
                scenario.AddContextFor(testFixtureType);
                _scenarios.Add(scenario);
            }
        }

        public static Concern Create(Type testFixtureType)
        {
            string name = testFixtureType.GetName(NamingConvention.Concern);

            return name.IsEmpty() ? new NullConcern() : new Concern(name);
        }
    }

    public class NullConcern : Concern
    {
        public NullConcern() 
            : base(string.Empty)
        {
        }
    }
}